<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/23 0023
 * Time: 16:09
 */

namespace Api\Controller;


class ShopFansController extends BaseController
{
    protected $mid;
    protected $member;
    protected $table = 'ShopFans';
    public function __construct()
    {
        parent::__construct();
        //验证用户
        $openid = I('request.openid','');
        empty($openid) && $this->error('openid缺失！');
        $member = M('Usermember')->where(['openid' => $openid])->find();
        empty($member) && $this->error('用户不存在！');
        $this->mid = $member['id'];
        $this->member = $member;
    }

    /**
     * 根据广告投放屏幕查询用户列表
     * @param $id int 分组id
     */
    public function read($id)
    {
        $shop = M('Shop')->where('user_id='.$this->mid)->field('id')->find();
        empty($shop) && $this->error('请求错误！');
        $where['sid'] = $shop['id'];
        $where['order_list_id'] = $id;
        $list = M($this->table)->where($where)->select();
        // 查询用户信息
        $mids = array_unique(array_column($list,'mid'));
        $member = M('Usermember')->where(['id' => array('in',$mids)])->field('id,username,head_icon')->select();
        $this->success('获取成功！',$member);
    }
}